package StudyCode.summary.BufferAndChannel;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ChangesMemoryMappedByteBuffer {
	public static void main(String[] argv) throws Exception {
		try {
			File file = new File("E:/Copy/1.txt");
			FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
			MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_WRITE, 0, (int) channel.size());
			buf.put(0, (byte) 0xFF);
			buf.force();
			channel.close();
			System.out.println("更改内存映射的 ByteBuffer 成功");
		} catch (IOException e) {
		}
	}
}
